﻿package mortal.game.view.common.pageSelect
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.guide.data.*;

    public class PageSelecter extends GSprite
    {
        protected var _mode:String = "简单状态";
        protected var _firstPageBtn:GButton;
        protected var _prevPageBtn:GButton;
        protected var _pageText:TextBox;
        protected var _nextPageBtn:GButton;
        protected var _lastPageBtn:GButton;
        protected var _spInputContainer:Sprite;
        protected var _tf1:GTextFiled;
        protected var _tf2:GTextFiled;
        protected var _tiPage:GTextInput;
        protected var _btnJump:GButton;
        protected var _currentPage:int = 1;
        protected var _maxPage:int = 1;
        protected var _pageTextBoxSize:int = 40;
        public static const SingleMode:String = "简单状态";
        public static const CompleteMode:String = "完整状态";
        public static const InputMode:String = "带输入框的状态";

        public function PageSelecter()
        {
            return;
        }// end function

        public function get maxPage() : int
        {
            return this._maxPage;
        }// end function

        public function set maxPage(param1:int) : void
        {
            this._maxPage = param1;
            if (this._maxPage <= 0)
            {
                this._maxPage = 1;
            }
            if (this._currentPage > this._maxPage)
            {
                this._currentPage = this._maxPage;
            }
            if (this._pageText)
            {
                this.updateText();
            }
            return;
        }// end function

        public function get currentPage() : int
        {
            return this._currentPage;
        }// end function

        public function set currentPage(param1:int) : void
        {
            this._currentPage = param1 > 0 ? (param1) : (1);
            this._currentPage = param1 < this.maxPage ? (this._currentPage) : (this.maxPage);
            if (this._pageText)
            {
                this.updateText();
            }
            return;
        }// end function

        public function updatePageTxt(param1:int) : void
        {
            this.gotoPage(param1);
            return;
        }// end function

        protected function updateText() : void
        {
            this._pageText.textField.text = this._currentPage + "/" + this._maxPage;
            this._nextPageBtn.enabled = this.currentPage < this.maxPage;
            this.updateFilter(this._nextPageBtn);
            this._prevPageBtn.enabled = this.currentPage > 1;
            this.updateFilter(this._prevPageBtn);
            this._firstPageBtn.enabled = this.currentPage > 1;
            this.updateFilter(this._firstPageBtn);
            this._lastPageBtn.enabled = this.currentPage < this.maxPage;
            this.updateFilter(this._lastPageBtn);
            return;
        }// end function

        protected function updateFilter(param1:GButton) : void
        {
            param1.filters = param1.enabled ? ([]) : ([FilterConst.colorFilter2]);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._firstPageBtn = UIFactory.gButton("", 0, 0, 22, 22, this, "FirstPageButton");
            this._firstPageBtn.configEventListener(MouseEvent.CLICK, this.firstPage);
            this._prevPageBtn = UIFactory.gButton("", 0, 0, 22, 22, this, "PrevPageButton");
            this._prevPageBtn.configEventListener(MouseEvent.CLICK, this.prevPage);
            this._pageText = UICompomentPool.getUICompoment(TextBox) as TextBox;
            this._pageText.createDisposedChildren();
            this._pageText.bgWidth = this._pageTextBoxSize;
            this._pageText.bgHeight = 20;
            this._pageText.htmlText = "";
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            this._pageText.textField.defaultTextFormat = _loc_1;
            this.addChild(this._pageText);
            this._nextPageBtn = UIFactory.gButton("", 0, 0, 22, 22, this, "NextPageButton");
            this._nextPageBtn.configEventListener(MouseEvent.CLICK, this.nextPage);
            this._nextPageBtn.name = AutoGuideClickChildNames.PageSelector_BtnNextName;
            this._lastPageBtn = UIFactory.gButton("", 0, 0, 22, 22, this, "LastPageButton");
            this._lastPageBtn.configEventListener(MouseEvent.CLICK, this.lastPage);
            this._spInputContainer = UICompomentPool.getUICompoment(Sprite) as Sprite;
            this._tf1 = UIFactory.gTextField(Language.getString(41614), 0, 2, 30, 20, this._spInputContainer, GlobalStyle.textFormatAnjin);
            this._tiPage = UIFactory.gTextInput(30, 1, 75, 20, this._spInputContainer);
            this._tiPage.restrict = "0-9";
            this._tf2 = UIFactory.gTextField(Language.getString(41615), 107, 2, 18, 20, this._spInputContainer, GlobalStyle.textFormatAnjin);
            this._btnJump = UIFactory.gButton(Language.getString(41616), 125, -1, 59, 22, this._spInputContainer);
            this._tiPage.configEventListener(Event.CHANGE, this.tiChangeHandler);
            this._btnJump.configEventListener(MouseEvent.CLICK, this.onJump);
            this.drawNow();
            this.updateText();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._firstPageBtn.dispose();
            this._prevPageBtn.dispose();
            this._pageText.dispose();
            this._nextPageBtn.dispose();
            this._lastPageBtn.dispose();
            this._tiPage.dispose();
            this._btnJump.dispose();
            this._tf1.dispose();
            this._tf2.dispose();
            UIFactory.disposeSprite(this._spInputContainer);
            this._firstPageBtn = null;
            this._prevPageBtn = null;
            this._pageText = null;
            this._nextPageBtn = null;
            this._lastPageBtn = null;
            this._tiPage = null;
            this._btnJump = null;
            this._tf1 = null;
            this._tf2 = null;
            this._spInputContainer = null;
            super.disposeImpl(param1);
            return;
        }// end function

        protected function drawNow() : void
        {
            var _loc_1:Vector.<DisplayObject> = null;
            this.removeAll();
            _loc_1 = new Vector.<DisplayObject>;
            if (this._mode == CompleteMode || this._mode == InputMode)
            {
                _loc_1.push(this._firstPageBtn);
                _loc_1.push(this._prevPageBtn);
                _loc_1.push(this._pageText);
                _loc_1.push(this._nextPageBtn);
                _loc_1.push(this._lastPageBtn);
                if (this._mode == InputMode)
                {
                    _loc_1.push(this._spInputContainer);
                }
            }
            else
            {
                _loc_1.push(this._prevPageBtn);
                _loc_1.push(this._pageText);
                _loc_1.push(this._nextPageBtn);
            }
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_1.length)
            {
                
                _loc_1[_loc_3].x = _loc_2;
                _loc_1[_loc_3].y = _loc_1[_loc_3] is TextBox ? (1) : (0);
                _loc_2 = _loc_2 + (_loc_1[_loc_3].width + 1);
                if (_loc_1[_loc_3] is GButton)
                {
                    (_loc_1[_loc_3] as GButton).drawNow();
                }
                this.addChild(_loc_1[_loc_3]);
                _loc_3++;
            }
            return;
        }// end function

        protected function removeAll() : void
        {
            var _loc_1:* = this.numChildren;
            var _loc_2:* = _loc_1 - 1;
            while (_loc_2 >= 0)
            {
                
                this.removeChildAt(_loc_2);
                _loc_2 = _loc_2 - 1;
            }
            return;
        }// end function

        protected function prevPage(event:MouseEvent) : void
        {
            this.gotoPage((this._currentPage - 1));
            return;
        }// end function

        protected function nextPage(event:MouseEvent) : void
        {
            this.gotoPage((this._currentPage + 1));
            return;
        }// end function

        protected function firstPage(event:MouseEvent) : void
        {
            this.gotoPage(1);
            return;
        }// end function

        protected function lastPage(event:MouseEvent) : void
        {
            this.gotoPage(this._maxPage);
            return;
        }// end function

        protected function tiChangeHandler(event:Event) : void
        {
            var _loc_2:* = int(this._tiPage.text);
            _loc_2 = _loc_2 > this.maxPage ? (this.maxPage) : (_loc_2);
            _loc_2 = _loc_2 < 1 ? (1) : (_loc_2);
            this._tiPage.text = _loc_2.toString();
            return;
        }// end function

        protected function onJump(event:MouseEvent) : void
        {
            this.gotoPage(int(this._tiPage.text));
            return;
        }// end function

        protected function gotoPage(param1:int) : void
        {
            param1 = param1 < 1 ? (1) : (param1);
            param1 = param1 > this._maxPage ? (this._maxPage) : (param1);
            if (this._currentPage != param1)
            {
                this._currentPage = param1;
                this.dispatchEvent(new Event(Event.CHANGE, true));
                this.updateText();
            }
            return;
        }// end function

        public function get mode() : String
        {
            return this._mode;
        }// end function

        public function set mode(param1:String) : void
        {
            this._mode = param1;
            this.drawNow();
            return;
        }// end function

        public function get pageTextBoxSize() : int
        {
            return this._pageTextBoxSize;
        }// end function

        public function set pageTextBoxSize(param1:int) : void
        {
            this._pageTextBoxSize = param1;
            this._pageText.bgWidth = this._pageTextBoxSize;
            this.drawNow();
            return;
        }// end function

        public function setbgStlye(param1:String, param2:GTextFormat) : void
        {
            this._pageText.setbgStlye(param1, param2);
            return;
        }// end function

    }
}
